package com.ftg.learn.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 *
 * @author 布衣
 */
public class Product {
    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        factory.setUsername("admin");    
        factory.setPassword("admin");
        try(
            Connection connection = factory.newConnection();
        ) {
            Channel channel = connection.createChannel();
            channel.queueDeclare("queue01",false, false, false, null);
            for (int i = 0; i < 100; i++) {
                channel.basicPublish("", "queue01", null, ("老大哥"+i).getBytes());
            }


        } catch (TimeoutException | IOException e) {
            throw new RuntimeException(e);
        }
    }

}
